import axios from "./axios";

class Env {
    constructor(){}

    // 新建环境
    createEnv(envObj:any){
        return axios.post('/api/env/create', {
            "envName": envObj.envName,
            "url": envObj.url,
            "groupID": envObj.groupID,
            "tagIDs": envObj.tagIDs,
            "browser": envObj.browser,
            "browserVersion": envObj.browserVersion,
            "os": envObj.os,
            "cookie": envObj.cookie,
            "mark": envObj.mark,
            "userAgent": envObj.userAgent,
            "timeZone": envObj.timeZone,
            "webRTC": envObj.webRTC,
            "location": envObj.location,
            "language": envObj.language,
            "acceleration": envObj.acceleration,
            "canvas": envObj.canvas,
            "deviceName": envObj.deviceName,
            "resolution": envObj.resolution,
            "mac": envObj.mac,
            "webgl": envObj.webgl,
            "webGLCorp": envObj.webGLCorp,
            "webGLRender": envObj.webGLRender,
            "doNotTrack": envObj.doNotTrack,
            "audioContext": envObj.audioContext,
            "mediaDevice": envObj.mediaDevice,
            "speechVoice": envObj.speechVoice,
            "concurrent": envObj.concurrent,
            "mem": envObj.mem,
            "mOrder": parseInt(envObj.mOrder)
        });
    }

    // 编辑环境
    updateEnv(envObj:any){
        return axios.post('/api/env/update', {
            "id": parseInt(envObj.id),
            "envName": envObj.envName,
            "url": envObj.url,
            "groupID": envObj.groupID,
            "tagIDs": envObj.tagIDs,
            "browser": envObj.browser,
            "browserVersion": envObj.browserVersion,
            "os": envObj.os,
            "cookie": envObj.cookie,
            "mark": envObj.mark,
            "userAgent": envObj.userAgent,
            "timeZone": envObj.timeZone,
            "webRTC": envObj.webRTC,
            "location": envObj.location,
            "language": envObj.language,
            "acceleration": envObj.acceleration,
            "canvas": envObj.canvas,
            "deviceName": envObj.deviceName,
            "resolution": envObj.resolution,
            "mac": envObj.mac,
            "macEnable": envObj.macEnable,
            "webglMetaEnable": envObj.webglMetaEnable,
            "webgl": envObj.webgl,
            "webGLCorp": envObj.webGLCorp,
            "webGLRender": envObj.webGLRender,
            "doNotTrack": envObj.doNotTrack,
            "audioContext": envObj.audioContext,
            "mediaDevice": envObj.mediaDevice,
            "speechVoice": envObj.speechVoice,
            "concurrent": envObj.concurrent,
            "mem": envObj.mem,
            "mOrder": parseInt(envObj.mOrder)
        });
    }

    

    // 获取环境信息列表
    fetchEnv(envName:any, groupId:any, tagIds:any, page:any, pageSize:any){
        return axios.post('/api/env/fetch', {envName, groupId, tagIds, page, pageSize});
    }

    // 获取指定环境信息
    fetchEnvById(id:any){
        id = parseInt(id);
        return axios.post('/api/env/fetchById', {id});
    }

    // 获取指定环境信息
    fetchEnvByEnvID(envID:any){
        return axios.post('/api/env/fetchByEnvID', {envID});
    }

    // 删除环境
    delEnv(id:any){
        return axios.post('/api/env/delete', {id});
    }

    //创建环境标签
    createEnvTag(tagName:any, mOrder:any) {
        mOrder = parseInt(mOrder);
        return axios.post('/api/envtag/create', {tagName, mOrder});
    }

    // 环境标签
    fetchEnvTag(tagName:any, page:any, pageSize:any){
        return axios.post('/api/envtag/fetch', {tagName, page, pageSize});
    }

    // 删除环境标签
    delteEnvTag(id:any){
        return axios.post('/api/envtag/delete', {id});
    }

    //更新环境标签
    updateEnvTag(id:any, tagName:any, mOrder:any) {
        mOrder = parseInt(mOrder);
        return axios.post('/api/envtag/update', {id, tagName, mOrder});
    }

    //创建环境分组
    createEnvGroup(groupName:any, mOrder:any) {
        mOrder = parseInt(mOrder);
        return axios.post('/api/envgroup/create', {groupName, mOrder});
    }

    // 环境分组
    fetchEnvGroup(groupName:any, page:any, pageSize:any){
        return axios.post('/api/envgroup/fetch', {groupName, page, pageSize});
    }

    // 删除环境分组
    delteEnvGroup(id:any){
        return axios.post('/api/envgroup/delete', {id});
    }

    //创建环境分组
    updateEnvGroup(id:any, groupName:any, mOrder:any) {
        mOrder = parseInt(mOrder);
        return axios.post('/api/envgroup/update', {id, groupName, mOrder});
    }

    // 导出选中的环境
    exportEnv(ids:any){
        return axios.post('/api/env/export', {ids});
    }

    // 导入环境
    importEnv(groupID:any, file:any ){
        var formData = new FormData();
        var jsonfile = file;
        formData.append("file", file);
        formData.append("groupID", groupID);
        return axios.postForm('/api/env/import', formData);
    }
}

export default new Env();